package com.steven.ourcontest.collect.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.steven.ourcontest.R
import com.steven.ourcontest.chat.bean.Friend
import com.steven.ourcontest.collect.bean.TeamCollection
import com.steven.ourcontest.forum.bean.DiscussBean
import com.steven.ourcontest.me.widget.GlideRoundTransform
import com.steven.ourcontest.net.NetConstants
import com.steven.ourcontest.utils.DateUtil

class TeamCollectionListAdapter(private val context: Context, private val itemClickListener: ((teamId: Long) -> Unit)) :
    RecyclerView.Adapter<ViewHolder>() {
    val listData by lazy {
        ArrayList<TeamCollection>()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflater =
            LayoutInflater.from(context).inflate(R.layout.item_team_collect, parent, false)
        return ViewHolder(inflater)
    }

    override fun getItemCount(): Int {
        return listData.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val itemData = listData[position]
        holder.apply {
            tv_name?.text = listData[position].uname
            Glide.with(context)
                .load(NetConstants.ICON_BASE_URL + itemData.iconUrl)
                .error(R.drawable.aio_image_fail)
                .apply(
                    RequestOptions.bitmapTransform(
                        GlideRoundTransform(
                            context,
                            10
                        )
                    )
                )
                .into(iv_icon)
            tv_team_name?.text = itemData.teamName
            itemView.setOnClickListener {
                itemClickListener.invoke(itemData.teamId)
            }
        }
    }
}

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    val iv_icon: ImageView = itemView.findViewById(R.id.iv_icon)
    val tv_name: TextView? = itemView.findViewById(R.id.tv_leader_name)
    val tv_team_name: TextView? = itemView.findViewById(R.id.tv_team_name)
}
